using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class bossbullet : MonoBehaviour
{
    private float speed = 3.5f;
    GameObject player;

    private void Start()
    {
        player = GameObject.FindGameObjectWithTag("Player");
        GameObject.Destroy(gameObject, 2.7f);
    }

    private void Update()
    {
        Move();
    }

    private void Move()
    {
        Vector3 dir = new Vector3();
        if(player != null)
        {
            dir = player.transform.position - transform.position;
            dir = dir.normalized;
            transform.position += speed*dir*Time.deltaTime;
        }
    }

    private void OnTriggerEnter2D(Collider2D other)
    {
        if(other.tag == "Player")
        {
            if (other.GetComponent<Player>().GetCurState() == false)
            {
                return;
            }

            other.GetComponent<Player>().Hurt();
            GameObject.Destroy(gameObject);
        }
    }

}
